<template>
  <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick" v-if='model.roundList?.length'>
    <template>
      <el-tab-pane
        v-for="(item,index) in model.roundList"
        :label="item.reviewRoundName"
        :name="index"
        :key="item.id"
      ></el-tab-pane>
    </template>
      <el-table
        :data="model.tableData"
        border
        style="width: 100%"
        v-loading="loading"
        v-if='model.tableData?.length'
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
      >
        <template #empty>
          <el-empty :image-size="80" description="暂无数据" height="200px"></el-empty>
        </template>
        <el-table-column type="index" label="序号">
          <template v-slot="scope">
            <span>{{scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="专家姓名" width="180"> </el-table-column>
        <el-table-column prop="deptName" label="所属单位"> </el-table-column>
        <el-table-column prop="expertGroupName" label="专家组别"> </el-table-column>
        <el-table-column prop="expertCategoryName" label="专家类型"></el-table-column>
        <el-table-column prop="reviewCommentsName" label="专家综合评审结论"></el-table-column>
        <el-table-column prop="reviewComments" label="评审意见和建议">
          <template #default="{ row }">
            <span type="primary" style="color:#f89c34;cursor: pointer;" @click="lookFor(row)">查看</span>
          </template>
        </el-table-column>
        <el-table-column prop="reviewFinishTime" label="评审时间"></el-table-column>
      </el-table>
  </el-tabs>

  <div class="text--info subtext sub-size" v-else>暂无专家评审意见</div>

  <review-dialog
    v-if="showReview"
    :reviewDetail="reviewDetail"
    @handleCancel="handleCancel"
  ></review-dialog>
</template>

<script lang="ts" setup>
  import ReviewDialog from "./ReviewDialog.vue";
import { ref, reactive,watch } from "vue";
import { getExpertRvwOpinion,getExpertList } from "/@/api/project";
const props = defineProps({
  projectInfo: {
    type: Object
  }
});
const activeName = ref("0");
const reviewDetail = ref({});
const projectInfo = ref({});
const loading = ref(false);
const showReview = ref(false);
const model = reactive({
  roundList:[],
  tableData: [],
  total: 0,
});

//查询专家审批轮次
const getExpertRoundList = async () => {
  try {
    if(projectInfo.value.stageStatus == 20 || projectInfo.value.stageStatus == 21){//变更和中止
      projectInfo.value.reviewStageCode = 6
    }else if(projectInfo.value.stageStatus == 22){
      projectInfo.value.reviewStageCode = 7
    }
    const { code, data } = await getExpertList({
      projectManageId: projectInfo.value.projectManageId,
      reviewStageCode:projectInfo.value.reviewStageCode || projectInfo.value.stageStatus,
      pageSize: 100
    });
    if (code === 200) {
      model.roundList = data.list;
      if(model.roundList?.length){
        const expertRvwId = model.roundList[0].id;
        getExpertRvwOpinionList(expertRvwId)
      }
    }
  } catch (err) {
    console.log(err);
  }
};

//获取专家审批意见
const getExpertRvwOpinionList = async (expertRvwId) => {
  try {
    loading.value = true;
    const { code, data } = await getExpertRvwOpinion({
      expertRvwId: expertRvwId,
      pageSize: 200
    });
    if (code === 200) {
      model.tableData = data.list;
      model.total = data.rows;
    }
  } catch (err) {
    console.log(err);
  } finally {
    loading.value = false;
  }
};

const lookFor = async (row) => {
  showReview.value = true;
  reviewDetail.value = row;
};

const handleCancel = async() => {
  showReview.value = false;
};

const handleClick = tab => {
  const expertRvwId = model.roundList[+tab.index].id
  getExpertRvwOpinionList(expertRvwId);
};

watch(
  () => props.projectInfo,
  async newVal => {
    projectInfo.value = newVal;
    await getExpertRoundList()
  }
);
</script>

<style lang="scss" scoped>
  .sub-size{
    font-size:14px;
    padding-top:20px;
    padding-bottom:10px;
  }
</style>
